<?php

namespace app\manage\controller;

use app\common\controller\Manage;
use app\common\model\RoomClass as roomClassModel;

class RoomClass extends Manage
{
    public $roomClassModel = null;
    
    public function initialize() {
        parent::initialize();
        $this->roomClassModel = new roomClassModel();
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        if($this->request->isAjax()) {
            $data = $this->roomClassModel->all();
            return [
                'code' => 0,
                'count' => count($data),
                'data' => $data
            ];
        }
        return $this->fetch();
    }
    
    public function edit()
    {
        $status = $this->roomClassModel->isUpdate()->save($this->request->post());
        return [
            'status'    => $status,
            'msg'       => '修改成功'       
        ];
    }
    
    public function add()
    {
        $status = $this->roomClassModel->save($this->request->post());
        return [
            'status'    => $status,
            'msg'       => '保存成功'       
        ];
    }
    
    public function del()
    {
        $status = $this->roomClassModel->destroy($this->request->post('id'));
        return [
            'status'    => $status,
            'msg'       => '删除成功'       
        ];
    }
}
